package com.jy.api.dao;

import com.jy.api.domain.OrderStatus;
import com.jy.api.domain.Reward;
import com.jy.api.util.MyDateUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.Date;
import java.util.List;

/**
 * Created by xiaohua on 2018/11/12.
 */
public interface RewardDao extends CrudRepository<Reward, String> {


    Page<Reward> findByStoreIdAndStatusAndEnabledOrderByCreateTimeDesc(String storeId,OrderStatus status,boolean enable, Pageable pageable);


    @Query(value = "SELECT ifnull(`member_name`,'') AS memberName, COUNT(`count`)  AS count  ,SUM(`total`) AS amount FROM `reward` WHERE `store_id` =? AND `status` ='FINISHED' GROUP BY `member_id`  ORDER BY amount DESC ", nativeQuery = true)
    List<Object[]> findSumRewardAndOrderByAmountAsc(String storeId);


    List<Reward> findByEmpIdAndPaymentTimeBetweenAndStatusAndEnabled(String empId, Date from, Date to, OrderStatus status, boolean enable);

    List<Reward> findByStoreIdAndPaymentTimeBetweenAndStatusAndEnabled(String storeId, Date from, Date to, OrderStatus status, boolean enable);

}
